import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'

export function add(data) {
  return request({
    url: 'api/sysUser/addOrSave',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/sysUser',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/sysUser/addOrSave',
    method: 'post',
    data
  })
}

export function editUser(data) {
  return request({
    url: 'api/sysUser/center',
    method: 'post',
    data
  })
}

export function searchUser(params) {
  return request({
    url: 'api/sysUser',
    method: 'get',
    params
  })
}
// 查询指标
export function gettarget(params) {
  return request({
    url: '/api/sysUser/target',
    method: 'get',
    params
  })
}

export function updatePass(user) {
  // encrypt(
  const data = {
    oldPassword:user.oldPass,
    newPassword:user.newPass
  }
  return request({
    url: 'api/sysUser/updatePassword',
    method: 'post',
    data
  })
}
export function resetPassword(data) {
  return request({
    url: 'api/sysUser/resetPassword',
    method: 'post',
    data
  })
}
// 保存系统用户指标
export function saveTarget(data) {
  return request({
    url: '/api/sysUser/saveTarget',
    method: 'post',
    data
  })
}

export function updateEmail(form) {
  const data = {
    password: encrypt(form.pass),
    email: form.email
  }
  return request({
    url: 'api/users/updateEmail/' + form.code,
    method: 'post',
    data
  })
}

// 导出系统用户
export function exportDe(data) {
  return request({
    url: 'api/sysUser/export',
    method: 'put',
    data
  })
}

// 导人系统用户
export function importDe(data) {
  return request({
    url: 'api/sysUser/import',
    method: 'post',
    data
  })
}

// 启用禁用系统用户
export function enableOrDisable(data) {
  return request({
    url: 'api/sysUser/enableOrDisable',
    method: 'post',
    data
  })
}

// 复制系统用户
export function copy(data) {
  return request({
    url: 'api/sysUser/copy',
    method: 'post',
    data
  })
}
export function rollbackApk(data) {
  return request({
    url: 'api/common/rollbackApk',
    method: 'post',
    data
  })
}

export default { add, edit, del, importDe, exportDe, enableOrDisable, copy,resetPassword ,gettarget,saveTarget}

